<?php

namespace App\Services\Game;
use App\DTOS\Admin\MemberKeepDTO;
use App\Models\Game\MemberKeep;
use App\Models\Game\MemberKeepPay;

class MemberKeepService
{
    public function paginate(MemberKeepDTO $DTO)
    {
        $perPage = $DTO->getLimit();
        $page = $DTO->getPage();
        $gameArea = $DTO->getGameArea();

        $model = MemberKeep::query();
        $createDateBegin = $DTO->getCreateDateBegin();
        $createDateEnd = $DTO->getCreateDateEnd();
        if ($createDateBegin) {
            $model->where('ymd','>=',$createDateBegin);
        }
        if ($createDateEnd){
            $model->where('ymd','<=',$createDateEnd);
        }
        if ($gameArea!==null) {
            $model->where('game_area',$gameArea);
        }

        return $model->orderByDesc('ymd')->paginate($perPage,'*','page',$page);
    }


    public function paypaginate(MemberKeepDTO $DTO)
    {
        $perPage = $DTO->getLimit();
        $page = $DTO->getPage();
        $gameArea = $DTO->getGameArea();

        $model = MemberKeepPay::query();
        $createDateBegin = $DTO->getCreateDateBegin();
        $createDateEnd = $DTO->getCreateDateEnd();
        if ($createDateBegin) {
            $model->where('ymd','>=',$createDateBegin);
        }
        if ($createDateEnd){
            $model->where('ymd','<=',$createDateEnd);
        }
        if ($gameArea!==null) {
            $model->where('game_area',$gameArea);
        }

        return $model->orderByDesc('ymd')->paginate($perPage,'*','page',$page);
    }
}
